/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaProcedimento.java
 *
 * Created on 13/12/2013, 21:27:27
 */
package views;

import config.LogErro;
import controllers.DimensaoController;
import controllers.ProcedimentoController;
import controllers.TabAuxController;
import java.awt.Frame;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import models.entidades.Dimensao;
import models.entidades.Ligacao;
import models.entidades.Procedimento;
import models.entidades.TabAux;
import views.utilitario.LigacaoAtributo;
import views.utilitario.ReferenciaAtributos;
import views.utilitario.TabelaDinamica;

/**
 *
 * @author Wenderson
 */
public class TelaProcedimento extends javax.swing.JDialog {
    
    private Frame parent;
    
    private Dimensao dimensao;
    private TabAux tabAux;
    
    private TabelaDinamica<ReferenciaAtributos> tabDimensao;
    private TabelaDinamica<ReferenciaAtributos> tabAuxiliar;
    private TabelaDinamica<LigacaoAtributo> tabLigacao;

    /** Creates new form TelaProcedimento */
    public TelaProcedimento(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        this.parent = parent;
        
        this.setLocationRelativeTo(parent);
        
        this.inicializaTabelas();
    }
    
    private void inicializaTabelas() {
        this.tabDimensao = new TabelaDinamica<ReferenciaAtributos>(new ReferenciaAtributos());
        this.jt_dimensao.setModel(this.tabDimensao);
        
        this.tabAuxiliar = new TabelaDinamica<ReferenciaAtributos>(new ReferenciaAtributos());
        this.jt_tabAuxiliar.setModel(this.tabAuxiliar);
        
        this.tabLigacao = new TabelaDinamica<LigacaoAtributo>(new LigacaoAtributo());
        this.jt_ligacao.setModel(this.tabLigacao);
    }
    
    private void popupAux() {
        TelaPopup popup = new TelaPopup(this.parent, true, TelaPopup.Captura.TAB_AUX);
        popup.setVisible(true);
        
        String retorno = popup.getRetorno();
        
        // PEGANDO CÓDIGO DA TABELA AUXILIAR
        int id = Integer.valueOf(retorno.split(";")[0]);
        
        // PEGANDO ESQUEMA DA TABELA AUXILIAR
        String esquema = retorno.split(";")[1].toString();
        
        // PEGANDO NOME DA TABELA AUXILIAR
        String nome = retorno.split(";")[2].toString();
        
        this.tabAux = new TabAux(id, esquema, nome);
        
        this.jtf_tabAuxiliar.setText(nome);        
    }
    
    private void popupDim() {
        try {
        TelaPopup popup = new TelaPopup(this.parent, true, TelaPopup.Captura.DIMENSAO);
        popup.setVisible(true);
        
        String retorno = popup.getRetorno();
        
        // PEGANDO CÓDIGO DA TABELA AUXILIAR
        int id = Integer.valueOf(retorno.split(";")[0]);
        
        // PEGANDO ESQUEMA DA TABELA AUXILIAR
        String esquema = retorno.split(";")[1].toString();
        
        // PEGANDO NOME DA TABELA AUXILIAR
        String nome = retorno.split(";")[2].toString();
        
        this.dimensao = new Dimensao(id, esquema, nome);
        
        this.jtf_dimensao.setText(nome);        
        } catch (Exception e) {
            LogErro.gravaErro(e);
        }        
    }
    
    private void tab1() {
        if (!this.dadosValidos()) {
            JOptionPane.showMessageDialog(null, "Há dados inválidos!");
            return;
        }
        
        ArrayList<ReferenciaAtributos> ref = (ArrayList<ReferenciaAtributos>) 
                DimensaoController.getAtributosDim(this.dimensao.getCdDimensao());
        
        this.tabDimensao.inserir(ref);
        
        
        ref = (ArrayList<ReferenciaAtributos>)
                TabAuxController.getAtributosAux(this.tabAux.getCdTabAux());
        
        this.tabAuxiliar.inserir(ref);
        
        this.jtp_principal.setSelectedIndex(1);
    }
    
    public void tab2() {
        Procedimento p = new Procedimento();
        p.setEsquema(this.jtf_esquema.getText());
        p.setNome(this.jtf_procedimento.getText());
        
        p.setTabAux(this.tabAux);
        p.setDimensao(this.dimensao);
        
                
        if (ProcedimentoController.inserir(p, this.tabLigacao.getList())) {
            JOptionPane.showMessageDialog(null, "Procedimento Inserido Com Sucesso.");
            this.limparDados();
            this.jtp_principal.setSelectedIndex(0);
        } else {
            JOptionPane.showMessageDialog(null, "Procedimento Não Foi Inserido.");
        }
    }
    
    private void limparDados() {
        this.jtf_procedimento.setText("");
        this.jtf_esquema.setText("");

        this.jtf_dimensao.setText("");
        this.jtf_tabAuxiliar.setText("");
        
        this.tabAux = null;
        this.dimensao = null;
    }
    
    private boolean dadosValidos() {
        String nome = this.jtf_procedimento.getText();
        String esquema = this.jtf_esquema.getText();
        
        if (nome != null && !nome.trim().isEmpty() && esquema != null && !esquema.trim().isEmpty()
            && this.dimensao != null && this.tabAux != null) {
            return true;
        }
        
        return false;
    }
    
    private void adicionaReferencia() {
        if (this.jt_tabAuxiliar.getSelectedRow() == -1 || this.jt_dimensao.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(null, "Selecione uma linha da Tabela Auxiliar e uma da Dimensão.");
            return;
        }
        
        int linhaAux = this.jt_tabAuxiliar.getSelectedRow();
        int linhaDim = this.jt_dimensao.getSelectedRow();
        
        ReferenciaAtributos refAux = this.tabAuxiliar.getValue(linhaAux);
        ReferenciaAtributos refDim = this.tabDimensao.getValue(linhaDim);
        
        LigacaoAtributo la = new LigacaoAtributo();
        la.setCdAux(refAux.getCodigo());
        la.setCdDim(refDim.getCodigo());
        
        la.setNomeAux(refAux.getNome());
        la.setNomeDim(refDim.getNome());
        
        la.setTrans(false);
        
        if (this.tabLigacao.exists(la)) {
            JOptionPane.showMessageDialog(null, "Linha já existente.");
        } else {
            this.tabLigacao.inserir(la);
        }
    }
    
    private void removeReferencia() {
        if (this.jt_ligacao.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(null, "Selecione uma linha da Tabela de Ligação.");
            return;
        }
        
        int linha = this.jt_ligacao.getSelectedRow();
        
        this.tabLigacao.remover(linha);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtp_principal = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtf_esquema = new javax.swing.JTextField();
        jtf_procedimento = new javax.swing.JTextField();
        jtf_dimensao = new javax.swing.JTextField();
        jtf_tabAuxiliar = new javax.swing.JTextField();
        jb_tabAuxiliar = new javax.swing.JButton();
        jb_dimensao = new javax.swing.JButton();
        jb_tab1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_tabAuxiliar = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jt_ligacao = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jt_dimensao = new javax.swing.JTable();
        jb_concluir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jtp_principal.setBackground(new java.awt.Color(102, 102, 102));
        jtp_principal.setEnabled(false);

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setText("Banco/Esquema:");

        jLabel2.setText("Procedimento:");

        jLabel3.setText("Dimensão:");

        jLabel4.setText("Tab. Auxiliar:");

        jtf_dimensao.setEditable(false);

        jtf_tabAuxiliar.setEditable(false);

        jb_tabAuxiliar.setText("...");
        jb_tabAuxiliar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_tabAuxiliarActionPerformed(evt);
            }
        });

        jb_dimensao.setText("...");
        jb_dimensao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_dimensaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtf_procedimento, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtf_tabAuxiliar)
                            .addComponent(jtf_dimensao))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jb_dimensao, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jb_tabAuxiliar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jtf_esquema, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jtf_esquema, jtf_procedimento});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(jtf_esquema, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(jtf_procedimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel3)
                    .addComponent(jtf_dimensao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_dimensao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel4)
                    .addComponent(jtf_tabAuxiliar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_tabAuxiliar))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jb_tab1.setText(">>");
        jb_tab1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_tab1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(129, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(129, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jb_tab1)
                .addGap(28, 28, 28))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                .addComponent(jb_tab1)
                .addContainerGap())
        );

        jtp_principal.addTab("Procedimento", jPanel1);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tab. Auxiliar"));

        jt_tabAuxiliar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jt_tabAuxiliar.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jt_tabAuxiliar);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Referência"));

        jt_ligacao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jt_ligacao.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jt_ligacao);

        jButton1.setText("+");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("-");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(54, 54, 54)
                        .addComponent(jButton2)
                        .addGap(79, 79, 79))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Dimensão"));

        jt_dimensao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jt_dimensao.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(jt_dimensao);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jb_concluir.setText("Concluir");
        jb_concluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_concluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(369, 369, 369)
                        .addComponent(jb_concluir)))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPanel4, jPanel6});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jb_concluir)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel4, jPanel5, jPanel6});

        jtp_principal.addTab("Referência", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtp_principal)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtp_principal, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jb_dimensaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_dimensaoActionPerformed
        this.popupDim();
    }//GEN-LAST:event_jb_dimensaoActionPerformed

    private void jb_tabAuxiliarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_tabAuxiliarActionPerformed
        this.popupAux();
    }//GEN-LAST:event_jb_tabAuxiliarActionPerformed

    private void jb_tab1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_tab1ActionPerformed
        this.tab1();
    }//GEN-LAST:event_jb_tab1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.adicionaReferencia();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.removeReferencia();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jb_concluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_concluirActionPerformed
        this.tab2();
    }//GEN-LAST:event_jb_concluirActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaProcedimento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaProcedimento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaProcedimento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaProcedimento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                TelaProcedimento dialog = new TelaProcedimento(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jb_concluir;
    private javax.swing.JButton jb_dimensao;
    private javax.swing.JButton jb_tab1;
    private javax.swing.JButton jb_tabAuxiliar;
    private javax.swing.JTable jt_dimensao;
    private javax.swing.JTable jt_ligacao;
    private javax.swing.JTable jt_tabAuxiliar;
    private javax.swing.JTextField jtf_dimensao;
    private javax.swing.JTextField jtf_esquema;
    private javax.swing.JTextField jtf_procedimento;
    private javax.swing.JTextField jtf_tabAuxiliar;
    private javax.swing.JTabbedPane jtp_principal;
    // End of variables declaration//GEN-END:variables
}
